//
//  MessageNotiftViewController.m
//  CityFire
//
//  Created by Liuyz on 2017/8/2.
//  Copyright © 2017年 刘养柱. All rights reserved.
//

#import "MessageNotiftViewController.h"
#import "MessageViewModel.h"
#import "NSUserDefaults+Tools.h"

@interface MessageNotiftViewController ()

@property (weak, nonatomic) IBOutlet UISwitch *receiveMsgSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *soundSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *vibrateSwitch;
@property (nonatomic, strong) MessageViewModel *messageViewModel;

@end

@implementation MessageNotiftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = kMessageNotify_TITLE;
    
    self.receiveMsgSwitch.on = [[NSUserDefaults readUserDataWithKey:kNSUSERDEFAULT_KEY_ISMINKD] boolValue];
    self.soundSwitch.on = [[NSUserDefaults readUserDataWithKey:kNSUSERDEFAULT_KEY_ISSOUND] boolValue];
    self.vibrateSwitch.on = [[NSUserDefaults readUserDataWithKey:kNSUSERDEFAULT_KEY_VIBRATE] boolValue];
}

- (IBAction)changeSwitch:(UISwitch *)sender
{
    NSString *remind=@"0";
    NSString *sound=@"0";
    NSString *vibrate=@"0";
    remind = [NSUserDefaults readUserDataWithKey:kNSUSERDEFAULT_KEY_ISMINKD];
    sound = [NSUserDefaults readUserDataWithKey:kNSUSERDEFAULT_KEY_ISSOUND];
    vibrate = [NSUserDefaults readUserDataWithKey:kNSUSERDEFAULT_KEY_VIBRATE];
    NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
    
    switch (sender.tag - 3333) {
        case 0:
        {
            remind = sender.on ? @"1" : @"0";
        }
            break;
        case 1:
        {
            sound = sender.on ? @"1" : @"0";
        }
            break;
        case 2:
        {
            vibrate = sender.on ? @"1" : @"0";
        }
            break;
        default:
            break;
    }
    [tempDic setObject:remind forKey:@"remind"];
    [tempDic setObject:sound forKey:@"sound"];
    [tempDic setObject:vibrate forKey:@"vibrate"];
    [self.messageViewModel setRemind:tempDic];
}

- (MessageViewModel *)messageViewModel
{
    if (_messageViewModel == nil) {
        _messageViewModel = [[MessageViewModel alloc] init];
    }
    
    return _messageViewModel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
